package com.auction.mapper;

import com.auction.dto.AuctionCategoryPageQuery;
import com.auction.pojo.AuctionCategory;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 插入类目
     * 
     * @param category
     */
    void insert(AuctionCategory category);

    /**
     * 更新类目
     * 
     * @param category
     */
    void update(AuctionCategory category);

    /**
     * 删除类目
     * 
     * @param id
     */
    @Delete("DELETE FROM auction_category WHERE id = #{id}")
    void delete(@Param("id") Long id);

    /**
     * 根据ID查询类目
     * 
     * @param id
     * @return
     */
    @Select("SELECT * FROM auction_category WHERE id = #{id}")
    AuctionCategory selectById(@Param("id") Long id);

    /**
     * 分页查询类目
     * 
     * @param categoryPageQuery
     * @return
     */
    Page<AuctionCategory> pageQuery(AuctionCategoryPageQuery categoryPageQuery);

    /**
     * 根据名称查询类目
     *
     * @param name
     * @return
     */

    List<AuctionCategory> selectByName(@Param("name") String name);

    /**
     * 检查类目下是否有拍卖品
     * 
     * @param categoryId
     * @return 拍卖品数量
     */
    @Select("SELECT COUNT(*) FROM auction WHERE category_id = #{categoryId}")
    int countAuctionsByCategoryId(@Param("categoryId") Long categoryId);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    List<AuctionCategory> list(Integer type);
}